#include "QueryPlanNode.h"

SumNode::SumNode(int inPipeId, int outPipeId, Function *computeMe, Pipe *inPipe, Pipe *outPipe) : QueryPlanNode(sum),
		inPipeId(inPipeId), outPipeId(outPipeId), computeMe(computeMe), inPipe(inPipe), outPipe(outPipe) {
}

void SumNode::Print(){
	cout<<"********\n";
	cout<<"Sum\n";
	cout<<"Input pipe ID "<<inPipeId<<endl;
	cout<<"Output pipe ID "<<outPipeId<<endl;
	cout<<"Sum function:\n";
	computeMe->Print();
	cout<<"********\n";
}

void SumNode::Execute(){
	sm.Use_n_Pages(RUN_LENGTH);
	sm.Run(*inPipe, *outPipe, *computeMe);
}

void SumNode::Wait(){
	sm.WaitUntilDone();
}

void SumNode::Clean(){
    delete inPipe, outPipe, out_pipe;
}
